
class GetCommodity:

   def  getByCategory(self,list,category):
       asin=[]
       numOfCommodity=[]
       for i in range(0,len(list)):
           if(list[i]['category']==category):
              if(list[i]['ASIN'] in asin):
                  numOfCommodity[asin.index(list[i]['ASIN'])]=numOfCommodity[asin.index(list[i]['ASIN'])]+1
              else:
                  numOfCommodity.append(1)
                  asin.append(list[i]['ASIN'])
        
       for i in range(0,len(asin)):
            for j in range(0,len(asin)-1):
                if(asin[j]<asin[j+1]):
                    temp1=asin[j]
                    asin[j]=asin[j+1]
                    asin[j+1]=temp1
                    temp2=numOfCommodity[j]
                    numOfCommodity[j]=numOfCommodity[j+1]
                    numOfCommodity[j+1]=temp2
       return {'category': category,'asin':asin[0],'num':numOfCommodity[0]}